package com.zecan.rabbitmq.rabbitmq.contrller;

import com.zecan.rabbitmq.rabbitmq.config.PriorityConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: lenovo
 * \* Date: 2022/4/21
 * \* Time: 12:11
 * \* Description:
 * \
 */
@RestController
@RequestMapping("/priority")
public class PriorityController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/{message}/{priority}")
    public void sendMsg(@PathVariable("message") String message,
                        @PathVariable("priority") Integer priority) {

        Message msg = MessageBuilder.withBody(message.getBytes()).setPriority(priority).build();

        rabbitTemplate.convertAndSend(PriorityConfig.PRIORITY_EXCHANGE_NAME,
                PriorityConfig.PRIORITY_ROUTING_KEY, msg );
    }
}
